/**
 * @file
 * @auth jinguangguo
 * @date 2016/11/30
 */
 
export default {

    /**
     * 是否是移动端
     * @returns {boolean}
     */
    isMobile() {
        let userAgentInfo = navigator.userAgent;
        let Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
        let flag = false;
        for (let v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = true;
                break;
            }
        }
        return flag;
    },

    /**
     * 是否是邮箱
     * @param email
     * @returns {boolean}
     */
    isEmail(email) {
        const regEmail = /^([a-zA-Z0-9]+[_|\_|\.\-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        return regEmail.test(email);
    },

    /**
     * 是否是手机号
     * @param phone
     * @returns {boolean}
     */
    isPhone(phone) {
        phone = phone + '';
        const phoneReg =   /^((13[0-9])|(14[57])|(15[0-35-9])|(17[0-9])|(18[0-9]))\d{8}$/;
        return phoneReg.test(phone);
    },

    /**
     * 获取银行卡后4位
     * @param bankCode
     * @returns {string}
     */
    getSuffixBankCode(bankCode) {
        bankCode = bankCode + '';   // 强制转变成字符串
        return bankCode.substr(-4);
    }
}